package com.nari.ncps.screen.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nari.ncps.screen.mapper.MonitorMapper;
import com.nari.ncps.screen.model.Monitor;
import com.nari.ncps.screen.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 全产业一体化-监控设备获取全部列表
 *
 * @author wanghuiqiang
 * @since 2025-10-26
 */
@Service
public class MonitorServiceImpl extends ServiceImpl<MonitorMapper, Monitor> implements MonitorService {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    /**
     * 全产业一体化-监控设备获取全部列表
     * @param plateId 板块id
     * @return 监控设备获取全部列表
     */
    @Override
    public List<Monitor> getMonitor(Integer plateId) {
        String sql = "SELECT " +
                    "plate_id, " +
                    "plate_name, " +
                    "company_id, " +
                    "company_name, " +
                    "hls_child, " +
                    "hls_main, " +
                    "hik_code " +
//                    "FROM my_screen_emergy.dim_comm_monitor_info " +
                    "FROM dim_comm_monitor_info " +
                    "WHERE display = 1 " + "AND plate_id = ? " +
                    "GROUP BY plate_id, plate_name, company_id, company_name,hls_child, hls_main, hik_code " ;
                    //"ORDER BY sort_value ";

        List<Map<String, Object>> results = jdbcTemplate.queryForList(sql, plateId);
        System.out.println("results = " + results);
        
        List<Monitor> result = new ArrayList<>();
        for (Map<String, Object> row : results) {
            Monitor monitor = new Monitor();
            row.get("plate_id");
            monitor.setPlateId((Long) row.get("plate_id"));
            monitor.setPlateName((String) row.get("plate_name"));
            monitor.setCompanyId((Long) row.get("company_id"));
            monitor.setCompanyName((String) row.get("company_name"));
            monitor.setHlsChild((String) row.get("hls_child"));
            monitor.setHlsMain((String) row.get("hls_main"));
            monitor.setHikCode((String) row.get("hik_code"));
            result.add(monitor);
        }
        return result;
    }

}